package com.suypower.carManage.action;

import com.jarp.db.DAO;
import com.opensymphony.xwork2.ActionSupport;
import com.suypower.carManage.comm.ConstUtil;

import javax.servlet.ServletException;

public class BasicInformationAction extends ActionSupport {

    private String id;
    private String code;
    private String attributes;
    private String type;
    private String price;
    private String brand;
    private String displacement;
    private String purchase_date;
    private String use_date;
    private String company;
    private String department;
    private String manufacturer;
    private String driver;
    private String logo;
    private String gps;
    private String vehicleuse;
    private String states;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getAttributes() {
        return attributes;
    }

    public void setAttributes(String attributes) {
        this.attributes = attributes;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getDisplacement() {
        return displacement;
    }

    public void setDisplacement(String displacement) {
        this.displacement = displacement;
    }

    public String getPurchase_date() {
        return purchase_date;
    }

    public void setPurchase_date(String purchaseDate) {
        purchase_date = purchaseDate;
    }

    public String getUse_date() {
        return use_date;
    }

    public void setUse_date(String useDate) {
        use_date = useDate;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public String getGps() {
        return gps;
    }

    public void setGps(String gps) {
        this.gps = gps;
    }

    public String getVehicleuse() {
        return vehicleuse;
    }

    public void setVehicleuse(String vehicleuse) {
        this.vehicleuse = vehicleuse;
    }

    public String getStates() {
        return states;
    }

    public void setStates(String states) {
        this.states = states;
    }

    public String execute() {
        String res = "";
        DAO dao = new DAO();
        String sql = "";
        if (logo.contains("1")) {
            logo = "1";
        } else if (logo.contains("2")) {
            logo = "2";
        } else {
            logo = "";
        }
        if (id != null && !id.equals("")) {
            sql = "UPDATE tb_car  SET  code = '" + code + "',  attributes = '"
                    + attributes + "',  type = '" + type + "',states='" + states + "',  price = '"
                    + price + "',  brand = '" + brand + "',  displacement = '"
                    + displacement + "',  purchase_date = '" + purchase_date
                    + "',  use_date = '" + use_date + "',  company = '"
                    + company + "',  department = '" + department
                    + "',  manufacturer = '" + manufacturer + "',  driver = '"
                    + driver + "',  logo = '" + logo + "',  gps = '" + gps
                    + "',  vehicleuse = '" + vehicleuse + "' where id=" + id;
        } else {
            sql = "INSERT INTO tb_car(code,attributes,type,states,price,brand,displacement,purchase_date,use_date,company,"
                    + "department,manufacturer,driver,logo,gps,vehicleuse)"
                    + "VALUES('"
                    + code
                    + "','"
                    + attributes
                    + "','"
                    + type
                    + "','"
                    + states
                    + "','"
                    + price
                    + "','"
                    + brand
                    + "','"
                    + displacement
                    + "',"
                    + "'"
                    + purchase_date
                    + "','"
                    + use_date
                    + "','"
                    + company
                    + "','"
                    + department
                    + "','"
                    + manufacturer
                    + "','"
                    + driver
                    + "','"
                    + logo
                    + "','"
                    + gps
                    + "','"
                    + vehicleuse
                    + "')";
        }

        int count = 0;
        try {
            count = dao.execCommand(ConstUtil.DBNAME, sql);
            if (count > 0) {
                res = this.SUCCESS;
            } else {
                res = this.ERROR;
            }
        } catch (ServletException e) {
            e.printStackTrace();
        }
        return res;
    }
}
